<?php
/**
 *  Pictures.php Created by : PhpStorm
 *
 * @author: 魏巍 <524314430@qq.com>
 * @date  : 2021/9/22 17:09
 */

namespace app\api\controller;

use app\admin\model\PictureCate;
use app\admin\model\PicturePictures;
use app\BaseController;
use think\App;

class Pictures extends Base
{
    protected $model;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new PicturePictures();
    }

    /**
     * @param int $page
     * @param int $limit
     * @param int $type
     *
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function index($page = 1, $limit = 10,$type = 0)
    {
        if ($type) {
            $where[] = ['cate_id', '=', $type];
        }
        $where[] = ['status', '<>', -1];
        $list = $this->model->getList($page, $where, 'upload_time desc', 'upload_time', $limit);
        $this->success($list);
    }

    /**
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function cate()
    {
        $list = PictureCate::field('id,title,image')->where('status',1)->select()->toArray();
        array_unshift($list,[
            'id'=> 0,
            'title'=> '全部',
            'image'=> '',
        ]);
        $this->success($list);
    }
}
